home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / MoofWars / Tim's Libraries / Scaling.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  3.1 KB  |  102 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Scaling.cp
  3.  
  4.     Contains:    Scaling implements a standard 2D canvas to draw a set of TGraphics and tiles into.
  5.                 It also provides a set of globals that allow the sprite's location to be relative
  6.                 to a specific camera location.
  7.  
  8.  
  9.     Written by: Timothy Carroll    
  10.  
  11.     Copyright:    Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
  12.  
  13.                 You may incorporate this Apple sample source code into your program(s) without
  14.                 restriction. This Apple sample source code has been provided "AS IS" and the
  15.                 responsibility for its operation is yours. You are not permitted to redistribute
  16.                 this Apple sample source code as "Apple sample source code" after having made
  17.                 changes. If you're going to re-distribute the source, we require that you make
  18.                 it clear in the source that the code was descended from Apple sample source
  19.                 code, but that you've made changes.
  20.  
  21.     Change History (most recent first):
  22.                 7/2/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  23.                 
  24.                 2/27/97        Timothy Carroll    Now properly includes error macros directly
  25.                 
  26.                 1/23/97     Timothy Carroll    Added include for Moofwars.h so that MrC will compile
  27.                 
  28.                 8/15/96        Timothy Carroll    Initial Release
  29.                 
  30.  
  31. */
  32.  
  33. #include "Scaling.h"
  34. #include "QDOffscreen.h"
  35. #include "Error Macros.h"
  36.  
  37. SInt32            gWorldCoordX = 0;
  38. SInt32            gWorldCoordY = 0;
  39. Rect            gClipRect = {0,0,0,0};
  40. SInt32            gClipCenterX = 0;
  41. SInt32            gClipCenterY = 0;
  42.  
  43. PixMapHandle    gDestPixMap = NULL;
  44. PixMapHandle    gBackPixMap = NULL;
  45. unsigned char    *gDestBaseAddr = NULL;
  46. unsigned char    *gBackBaseAddr = NULL;
  47. UInt32            gRowBytes;
  48.     
  49.  
  50.  
  51.  
  52.     
  53.  
  54.  
  55. /*************************************************************************************
  56.     SetDestinationBuffer
  57.     
  58.     This routine takes in the pix maps and sets up all the right variables for drawing.  Any
  59.     drawing using the TGraphic objects or TTiles must be done through a destination PixMap.
  60.     Ideally, if you are about to dispose of the buffers, you should call SetDestinationBuffer
  61.     with NULL for both pixmaps.  In the debugging version, this will cause an error if any
  62.     drawing is attempted through the NULL pix.
  63.     
  64.     If you specify a background pixmap, it must be the same dimensions, depth and rowbytes as
  65.     the main pix.
  66.  
  67. *************************************************************************************/
  68. void SetDestinationBuffer(PixMapHandle inDestPixMap, PixMapHandle inBackPixMap)
  69. {
  70.     // save the pix map info (so we can use it)
  71.     gDestPixMap = inDestPixMap;
  72.     gBackPixMap = inBackPixMap;
  73.  
  74.     // get info from the pix map
  75.     if (gDestPixMap != NULL)
  76.     {
  77.         gDestBaseAddr = ( unsigned char * ) GetPixBaseAddr( gDestPixMap );
  78.         gRowBytes = (*gDestPixMap )->rowBytes & 0x3fff;    
  79.     }
  80.     
  81.     if (gBackPixMap != NULL)
  82.         gBackBaseAddr = ( unsigned char * )GetPixBaseAddr (gBackPixMap );
  83.         
  84.     
  85. }
  86.  
  87.  
  88. void SetBufferClip(Rect *inClipRect)
  89. {
  90.     gClipRect = *inClipRect;
  91.     gClipCenterX  = (gClipRect.left + gClipRect.right) >> 1;
  92.     gClipCenterY  = (gClipRect.top  + gClipRect.bottom) >> 1;
  93. }
  94.  
  95.  
  96. // This function specifies the point in World Coordinates that coorsponds to the center
  97. // of the clipping rectangle.
  98. void SetWorldOrigin (SInt32 x, SInt32 y)
  99. {
  100.     gWorldCoordX = x;
  101.     gWorldCoordY = y;
  102. }